/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2025 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
  /* 取自"stm32f10x.h"文件，为了与标准库兼容 */
  typedef signed int 				s32;
  typedef signed short int 	s16;
  typedef signed char 			s8;

  typedef const s32 	sc32;  /*!< Read Only */
  typedef const s16 	sc16;  /*!< Read Only */
  typedef const s8 		sc8;   /*!< Read Only */

  typedef volatile s32	vs32;
  typedef volatile s16	vs16;
  typedef volatile s8		vs8;

  typedef volatile sc32 	vsc32;  /*!< Read Only */
  typedef volatile sc16 	vsc16;  /*!< Read Only */
  typedef volatile sc8 		vsc8;   /*!< Read Only */

  typedef unsigned int 				u32;
  typedef unsigned short int	u16;
  typedef unsigned char				u8;

  typedef const u32 	uc32;  /*!< Read Only */
  typedef const u16 	uc16;  /*!< Read Only */
  typedef const u8 		uc8;   /*!< Read Only */

  typedef volatile u32  vu32;
  typedef volatile u16 	vu16;
  typedef volatile u8  	vu8;

  typedef volatile uc32 	vuc32;  /*!< Read Only */
  typedef volatile uc16 	vuc16;  /*!< Read Only */
  typedef volatile uc8 		vuc8;   /*!< Read Only */
/* USER CODE END ET */

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */

/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */

/* USER CODE END EM */

/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);

/* USER CODE BEGIN EFP */
  void processReceivedData(void);
  void handleModeCommand(uint8_t cmd) ;
/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
#define AD9851_D2_Pin GPIO_PIN_2
#define AD9851_D2_GPIO_Port GPIOE
#define AD9851_D3_Pin GPIO_PIN_3
#define AD9851_D3_GPIO_Port GPIOE
#define AD9851_D4_Pin GPIO_PIN_4
#define AD9851_D4_GPIO_Port GPIOE
#define AD9851_D5_Pin GPIO_PIN_5
#define AD9851_D5_GPIO_Port GPIOE
#define AD9851_D6_Pin GPIO_PIN_6
#define AD9851_D6_GPIO_Port GPIOE
#define AD1_Pin GPIO_PIN_0
#define AD1_GPIO_Port GPIOA
#define AD2_Pin GPIO_PIN_1
#define AD2_GPIO_Port GPIOA
#define AD3_Pin GPIO_PIN_2
#define AD3_GPIO_Port GPIOA
#define AD9851_D7_Pin GPIO_PIN_7
#define AD9851_D7_GPIO_Port GPIOE
#define AD9851_FQUP_Pin GPIO_PIN_8
#define AD9851_FQUP_GPIO_Port GPIOE
#define AD9851_RST_Pin GPIO_PIN_9
#define AD9851_RST_GPIO_Port GPIOE
#define Relay_Pin GPIO_PIN_10
#define Relay_GPIO_Port GPIOE
#define AD9851_WCLK_Pin GPIO_PIN_9
#define AD9851_WCLK_GPIO_Port GPIOC
#define AD9851_D0_Pin GPIO_PIN_0
#define AD9851_D0_GPIO_Port GPIOE
#define AD9851_D1_Pin GPIO_PIN_1
#define AD9851_D1_GPIO_Port GPIOE

/* USER CODE BEGIN Private defines */
  //模式
#define MODE_NONE 0
#define MODE_MEASU 1
#define MODE_DETEC 2

  //测量步骤
#define MEAS_RI 0
#define MEAS_RO 1
#define MEAS_AV 2
#define MEAS_AF 3
#define MEAS_NOR 4
  //采样率
#define SR_1K 0
#define SR_100 1
#define SR_10K 2
#define SR_100K 3
#define SR_160K 4
#define SR_200K 5
#define SR_500K 6
  //采样电路增益
#define AV_VIN 67.0f
#define AV_IIN 106.0f
#define AV_VOUT 5.0f
  //电阻参数
#define R1_MEA 43000.0f
#define R2_MEA 15000.0f
#define R3_MEA 2000.0f
  //测量结果
#define MEA_INVALID 0xFFFFFFFF
  //故障原因
#define COMP_NONE 0
#define COMP_SHORT 1
#define COMP_OPEN 2
#define COMP_DOUBLE 3

/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
